<template>
  <!-- 添加或修改集装箱备案对话框 -->
  <el-dialog
    :title="title"
    :visible.sync="dialogVisible"
    width="1000px"
    append-to-body
    :close-on-click-modal="false"
    @close="close"
  >
    <el-form ref="form" :model="form" :rules="rules" label-width="98px" label-position="right"  class="flex-form" size="small">
          <el-form-item label="场所代码" prop="fieldCode">
        <el-input v-model.trim="form.fieldCode" placeholder="请输入场所代码" />
      </el-form-item>
    
          <el-form-item label="场所名称" prop="fieldName">
        <el-input v-model.trim="form.fieldName" placeholder="请输入场所名称" />
      </el-form-item>
    
          <el-form-item label="集装箱号" prop="contaNo">
        <el-input v-model.trim="form.contaNo" placeholder="请输入集装箱号" />
      </el-form-item>
    
          <el-form-item label="集装箱重量" prop="contaWt">
        <el-input v-model.trim="form.contaWt" placeholder="请输入集装箱重量" />
      </el-form-item>
    
          <el-form-item label="集装箱类型" prop="contaType">
        <el-select v-model.trim="form.contaType" placeholder="请选择集装箱类型">
          <el-option label="请选择字典生成" value="" />
        </el-select>
      </el-form-item>
    
          <el-form-item label="集装箱尺寸" prop="contaSize">
        <el-input v-model.trim="form.contaSize" placeholder="请输入集装箱尺寸" />
      </el-form-item>
    
          <el-form-item label="集装箱代码" prop="contaCode">
        <el-input v-model.trim="form.contaCode" placeholder="请输入集装箱代码" />
      </el-form-item>
    
          <el-form-item label="中文集装箱规格名称" prop="cnContaSpec">
        <el-input v-model.trim="form.cnContaSpec" placeholder="请输入中文集装箱规格名称" />
      </el-form-item>
    
          <el-form-item label="申报人" prop="declBy">
        <el-input v-model.trim="form.declBy" placeholder="请输入申报人" />
      </el-form-item>
    
          <el-form-item label="申报时间" prop="declTime">
        <el-date-picker clearable size="small"
                        v-model.trim="form.declTime"
                        type="date"
                        value-format="yyyy-MM-dd HH:mm:ss"
                        placeholder="选择申报时间">
        </el-date-picker>
      </el-form-item>
    
          <el-form-item label="审核状态" prop="declStatus">
        <el-select v-model.trim="form.declStatus" placeholder="请选择审核状态">
          <el-option
              v-for="dict in dict.type.conta_decl_status"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value"          ></el-option>
        </el-select>
      </el-form-item>
    
          <el-form-item label="申报重试次数，超过3分钟未回执，会自动再次发起申报，超过10次不在重试" prop="declRetryNum">
        <el-input v-model.trim="form.declRetryNum" placeholder="请输入申报重试次数，超过3分钟未回执，会自动再次发起申报，超过10次不在重试" />
      </el-form-item>
    
          <el-form-item label="审核时间" prop="auditDate">
        <el-date-picker clearable size="small"
                        v-model.trim="form.auditDate"
                        type="date"
                        value-format="yyyy-MM-dd HH:mm:ss"
                        placeholder="选择审核时间">
        </el-date-picker>
      </el-form-item>
    
          <el-form-item label="备注" prop="remark">
        <el-input v-model.trim="form.remark" type="textarea" placeholder="请输入内容" />
      </el-form-item>
    
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="close">取 消</el-button>
      </div>
  </el-dialog>
</template>

<script>
import { getContaRecord, addContaRecord, updateContaRecord } from "@/api/billsdecl/contaRecord";
export default {
  name: "ContaRecord-addEdit",
  props: {
    dialogType: {
      type: String,
      default: "add",
    },
    rowData: {
      type: Object,
      default: () => {},
    },
    dict:{}
  },
  data() {
    return {
      // 弹出层
      dialogVisible: false,
      // 标题
      title: "新增",
      // 表单参数
      form: {
                                              id: null,
                                                            fieldCode: null,
                                                            fieldName: null,
                                                            contaNo: null,
                                                            contaWt: null,
                                                            contaType: null,
                                                            contaSize: null,
                                                            contaCode: null,
                                                            cnContaSpec: null,
                                                            declBy: null,
                                                            declTime: null,
                                                            declStatus: null,
                                                            declRetryNum: null,
                                                            auditDate: null,
                                                            createBy: null,
                                                            createTime: null,
                                                            updateBy: null,
                                                            updateTime: null,
                                                            remark: null
                        
      },
      // 集装箱备案表格数据
      contaRecordList: [],
      // 表单校验
      rules: {
      }
    };
  },
  methods: {
    open() {
      this.dialogVisible = true;
      this.$nextTick(() => {
        if (this.dialogType == "add") {
          this.title = "新增";
        } else if (this.dialogType == "edit") {
          this.title = "编辑";
          this.loadDetail();
        } else if (this.dialogType == "detail") {
          this.title = "详情";
          this.loadDetail();
        }
      });
    },
    close() {
      this.$refs["form"].resetFields();
      this.dialogVisible = false;
    },

    // 获取详情
    loadDetail() {
      const id = this.rowData.id;
      getContaRecord(id).then((res) => {
        if (res.code == 200) {
          this.form = res.data;
                  }
      });
    },

    // 提交表单
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          let params = {
            ...this.form,
          };
          if (this.dialogType == "add") {
            addContaRecord(this.form).then(res => {
              if (res.code === 200) {
                this.$modal.msgSuccess("新增成功");
                this.close();
                this.$emit("handleQuery");
              }
            });
          } else {
            params.id = this.rowData.id;
            updateContaRecord(this.form).then(res => {
              if (res.code === 200) {
                this.$modal.msgSuccess("修改成功");
                this.close();
                this.$emit("handleQuery");
              }
            });
          }
        }
      });
    },
  },
};
</script>

<style lang="scss" scoped></style>
